<template>
  <div>
    <el-table :data="tableData" stripe style="width: 100%" max-height="600">
      <el-table-column prop="orderBy" label="排序" width="80">
      </el-table-column>
      <el-table-column prop="linkName" label="链接名称" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="linkHref" label="链接地址" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="createName" label="创建人" width="140">
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间" width="180">
      </el-table-column>
      <el-table-column label="操作" width="140">
        <template slot-scope="{ row }">
          <el-button-group>
            <el-button type="primary" size="mini" @click="handleEdit(row)"
              >编辑</el-button
            >
            <el-button type="danger" size="mini" @click="handleDelete(row)"
              >删除</el-button
            >
          </el-button-group>
        </template>
      </el-table-column>
      <div slot="empty" class="emptyBg">
        <el-empty :image-size="200"></el-empty>
      </div>
    </el-table>
  </div>
</template>

<script>
import {
  tbSysAddressQueryFriendlyLink,
  tbSysAddressDelete,
} from '@/api/admin/system/tbSysAddress.js'
import Bus from '@/utils/bus.js'
export default {
  data() {
    return {
      tableData: [],
    }
  },
  mounted() {
    this.getList()
    Bus.$on('refreshFriendLinkList', (v) => {
      this.getList()
    })
  },
  beforeDestroy() {
    Bus.$off('refreshFriendLinkList')
  },
  methods: {
    getList() {
      tbSysAddressQueryFriendlyLink().then((res) => {
        this.tableData = res.data.data
        this.$store.commit('SETFRIENDLINK', this.tableData)
      })
    },
    //编辑
    handleEdit(row) {
      Bus.$emit('showDialogFriendLinkAdd', row)
    },
    //删除确认
    handleDelete(row) {
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '删除',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.delete(row)
        })
        .catch(() => {})
    },
    //删除
    delete(row) {
      tbSysAddressDelete(row.id).then((res) => {
        this.getList()
        this.$message({
          message: '操作成功',
          type: 'success',
        })
      })
    },
  },
}
</script>